const app = getApp()
const{
  projectDetail,getProjectType
} =require('../../api/project')
const{
  taskList
} =require('../../api/task')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    project_id: '',
    id: '',
    project_detail: '',
    activeNames: ['2'],
    task_list: [],
    feedback_list_task: [],
    task_list_others: [],
    attendance_list_task: [],
    feedback_list_task_total:0,
    userInfo:null,
    pageNo:1,
    pageSize:10,
    finished: false,
    image_list: ['https://img.yzcdn.cn/public_files/2017/09/05/4e3ea0898b1c2c416eec8c11c5360833.jpg',
    'https://img.yzcdn.cn/public_files/2017/09/05/fd08f07665ed67d50e11b32a21ce0682.jpg'
    ],
    steps: [
      {
        text: '浇灌 - 草坪浇灌  2020/08/21 13:34:54',
        desc: '操作人员：张三<text class="look-photo">查看照片</text>',
        activeIcon: 'eye-o',
      },
      {
        text: '步骤二',
        desc: '操作人员：张三',
        activeIcon: 'eye-o',
      },
      {
        text: '步骤三',
        desc: '操作人员：张三',
        activeIcon: 'eye-o',
      },
      {
        text: '步骤四',
        desc: '操作人员：张三',
        activeIcon: 'eye-o',
      },
    ],
  },
  previewImage(e) {
    var current=e.target.dataset.imglist;
		wx.previewImage({
		  	current: '', // 当前显示图片的http链接
		  	urls: current // 需要预览的图片http链接列表
		})
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  goMyweather(e) {
    var current=e.target.dataset.location;
    wx.navigateTo({
      url: `/pages/myweather/index?location=${current}`,
    })
  },
  feedback_list_task(){
    let obj = {
      pageNo:this.data.pageNo,
      isFinish:this.data.finished,
      pageSize:this.data.pageSize,
      projectId:this.data.project_id,
      isFinish:1
    }
    wx.showLoading({
      title: '数据加载中~',
    })
    taskList(obj).then(res =>{
      let templateList=res.data.list;
      if(templateList && templateList.length){
        this.data.task_list=[...this.data.task_list,...templateList]

      }
      this.setData({
        feedback_list_task:this.data.task_list ||[],
        feedback_list_task_total:res.data.total
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
    });
  },
  toFeedbackPage() {

    wx.navigateTo({
      url: `/pages/canvas/index?pn=${this.data.project_detail.projectName}&id=${this.data.project_detail.id}&task_id=0&is_desc=false&do_type=3`,
    })
  },
  init() {
    wx.showLoading({
      title: '数据加载中~',
    })
    projectDetail({id:this.data.project_id}).then(res=>{
      this.setData({
        project_detail:res.data
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
    })
    //任务日志
    /*
    getProjectType({projectId:this.data.project_id,maintainId:'90010,90011,90012'}).then(res=>{

      this.setData({
        task_list:res.data,
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
    })
    */
    //进场留存
    getProjectType({projectId:this.data.project_id,maintainId:'90010,90035,90036'}).then(res=>{

      this.setData({
        task_list_others:res.data,
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
    })
    //获取拍照反馈数据
    this.feedback_list_task();
   /* getProjectType({projectId:this.data.project_id,isFinish:1, status:2}).then(res=>{
      
      this.setData({
        feedback_list_task:res.data,
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
    }) */
    //获取上班考勤数据
    getProjectType({projectId:this.data.project_id,maintainId:'90011,90012'}).then(res=>{
      this.setData({
        attendance_list_task:res.data,
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo:app.userInfo,
      isLogin:app.isLogin
    })
    wx.setNavigationBarTitle({
      title: options.pn && options.pn 
    })
    this.setData({
      project_id: options.id
    });
    this.init()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //this.init()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    this.onLoad()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(this.data.feedback_list_task.length)
    if(this.data.feedback_list_task_total == this.data.feedback_list_task.length){
        wx.showToast({
          title: '已经到底了!',
        })
    }else{
      if(!this.data.finished){
        this.data.pageNo=parseInt(this.data.pageNo+1)
        this.feedback_list_task();
      }
    }
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})